﻿@using CollegeShop.Infrastructure.Entities.Enum;
@{
    ViewBag.Title = "Group";
    Layout = "~/Views/Shared/_Admin.cshtml";
}
<div class="main-content" style="margin-left: 190px; min-height: 575px;">
    <div class="breadcrumbs" id="breadcrumbs">
        <ul class="breadcrumb">
            <li><i class="icon-home home-icon"></i><a href="/admin/index">Dashboard</a> </li>
            <li><a href="javascript:;">用户管理</a></li>
            <li class="active">管理员&管理员组管理</li>
        </ul>
        <!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <p>
            <a href="/admin/newmanager" class="btn btn-success">添加管理员</a>
            @*<a href="/admin/addunit" class="btn btn-primary">添加销售单元</a>*@
        </p>
        <div class="row-fluid">
            <div class="span7">
                <h3 class="row-fluid header smaller lighter purple">
                    <span class="span12">管理员分组</span>
                    <!-- /span -->
                </h3>
                <div class="span11">
                @{
                    Dictionary<int, List<CollegeShop.Infrastructure.Entities.Entity.User>> list = ViewBag.Staffs;
                    if (list != null && list.Any())
                    {
                        @:<ol class="dd-list">
                        foreach (var item in list)
                        {
                            <li class="dd-item dd2-item">
                                <div class="dd-handle dd2-handle">
                                    <i class="normal-icon icon-building blue bigger-130"></i><i class="drag-icon icon-move bigger-125">
                                    </i>
                                </div>
                                <div class="dd2-content" onclick="openframe(this)" style="cursor:pointer; margin-bottom:0px;">
                                    @(((CollegeShop.Infrastructure.Entities.Enum.SystemRole)item.Key).Mapping())
                                    <div class="pull-right action-buttons">
                                        <a class="blue" href="javascript:;" title="查看成员"> 
                                            <i class="icon-angle-right bigger-130"></i> 
                                        </a> 
                                    </div>
                                </div>
                                <ol class="dd-list" style="display:none;">
                                    @if (item.Value != null && item.Value.Any())
                                    {
                                        foreach (var user in item.Value)
                                        {
                                            <li class="dd-item dd2-item">
										        <div class="dd-handle dd2-handle">
											        <i class="normal-icon icon-user red bigger-130"></i>

											        <i class="drag-icon icon-move bigger-125"></i>
										        </div>
										        <div class="dd2-content">@user.NickName (@user.UserName)
                                                @if (user.SystemRole == SystemRole.Staff || user.SystemRole == SystemRole.Director)
                                                {
                                                    if(user.SalesUnit != null)
                                                    {
                                                        @:&nbsp;&nbsp;
                                                        @user.SalesUnit.SalesUnitName @:销售主管
                                                    }
                                                    if(user.SystemRole == SystemRole.Director)
                                                    {
                                                        @:(区域主管)
                                                    }
                                                }
                                                <div class="pull-right action-buttons">
                                                    <a class="red" onclick="deletemanager(this,'@user.UserName')" href="javascript:;" title="删除"> 
                                                        <i class="icon-trash bigger-130"></i> 
                                                    </a> 
                                                </div>
                                                </div>
									        </li>
                                        }
                                    }
								</ol>
                            </li>
                        }
                        @:</ol>
                    }
                }
                </div>
            </div>
            <div class="span5">
                <h3 class="row-fluid header smaller lighter purple">
                    <span class="span12">所有管理员</span>
                </h3>
                <div class="span12">
                    <ol class="dd-list">
                    @{
                        if (list != null && list.Any())
                        {
                            foreach (var item in list)
                            {
                                foreach (var g in item.Value)
                                {
                                    <li class="dd-item dd2-item">
                                        <div class="dd-handle dd2-handle">
                                            <i class="normal-icon icon-user red bigger-130"></i><i class="drag-icon icon-move bigger-125">
                                            </i>
                                        </div>
                                        <div class="dd2-content">
                                            @g.NickName (@g.UserName) - 
                                            @if (g.SystemRole == SystemRole.Staff || g.SystemRole == SystemRole.Director)
                                            {
                                                if (g.SalesUnit != null)
                                                {
                                                    @g.SalesUnit.SalesUnitName@:销售主管

                                                    if (g.SystemRole == SystemRole.Director)
                                                    {
                                                        @:(区域主管)
                                                    }
                                                }
                                                else
                                                {
                                                    @g.SystemRole.Mapping() @:(空置)
                                                }
                                            }
                                            else
                                            {
                                                @(g.SystemRole.Mapping())
                                            }</div>
                                    </li>
                                }
                            }
                        }
                        }
                    </ol>

                </div>
            </div>
        </div>
    </div>
</div>
@section tail{
    <script type="text/javascript">
        $(function () {
            $('#userBlock').trigger('click');
        });
        function openframe(sender) {
            $(sender).next('ol').slideToggle(200);
            var li = $(sender).children('div').children('a.blue').children('i')
            if (li.attr('class').indexOf('icon-angle-right') != -1) {
                li.removeClass('icon-angle-right').addClass('icon-angle-down');
            } else if (li.attr('class').indexOf('icon-angle-down') != -1) {
                li.removeClass('icon-angle-down').addClass('icon-angle-right');
            }
        }
        function deletemanager(sender, username) {
            if (confirm('确定要删除此用户吗？')) {
                $.ajax({
                    url: '/admin/deleteuser',
                    data: { username: username },
                    type: 'get',
                    success: function (res) {
                        if (res == '1') {
                            $(sender).parent().parent().parent().remove();
                        }
                    }
                });
            }
        }
    </script>
}